﻿/*
 * This software is the confidential and proprietary
 * information of NetBay
 * Such confidential information should not be disclosed
 * NetBay copyright(c) 2010
 */


#region Using
using System;
using System.ComponentModel;
using System.Data;
using System.Data.Common;
using System.Data.OracleClient;
using System.Data.SqlClient;
using Microsoft.Practices.EnterpriseLibrary.Data;
using NetBay.Core.DataAccess;
using NetBay.Core.Extensions;
using NetBay.Core.Log;
using Rio.Framework.RioManager;
using System.IO;

#endregion


namespace Rio.Doc.DataAccess

{
    public class DA_HistoricInfo
    {

        #region Enum
        /// <summary>
        /// List of DB functions to access data
        /// </summary>
        private enum DbFunction
        {
            [DescriptionAttribute("")]
            None,
            [DescriptionAttribute("P_HISTORIC_HISTO_Get_ByUserId")]
            GetHistoricConsultation,
            [DescriptionAttribute("P_HISTORIC_SEARCH_Delete")]
            DeleteSearcSave,


        }

        #endregion

        /// <summary>
        /// Call the stored procedure to trace the history consultation of a user 
        /// </summary>
        /// <param name="p_sAction"></param>
        /// <param name="p_lUserId"></param>
        /// <param name="p_iNbLine"></param>
        /// <param name="p_bSearchSave"></param>
        /// <returns></returns>
        public static IDataReader GetHistoricConsultation(string p_sAction, long p_lUserId, int p_iNbLine, bool p_bSearchSave)
        {
            LogManager.Instance().LogDebug("(p_sAction<" + p_sAction + "(p_lUserId<" + p_lUserId + "> (p_iNbLine<" + p_iNbLine + "> (p_bSearchSave<" + p_bSearchSave + ">...");
            var db = DbHelper.DataBase;

            var dbCommand = db.GetNewCommand(DbFunction.GetHistoricConsultation.szGetDescription());
            db.AddInParameter(dbCommand, "p_userId", DbType.Int64, p_lUserId);
            db.AddInParameter(dbCommand, "p_NbLig", DbType.Int32, p_iNbLine);
            db.AddInParameter(dbCommand, "p_sAction", DbType.String, p_sAction);
            db.AddInParameter(dbCommand, "p_SearchSave", DbType.Int32, Convert.ToInt32(p_bSearchSave));

            return db.ExecuteReader(dbCommand);
        }

        /// <summary>
        /// Delete Search Save
        /// </summary>
        /// <param name="p_lIdentifier"></param>
        public static void DeleteHistoricSearcSave(long p_lIdentifier)
        {
            try
            {
                LogManager.Instance().LogDebug("(p_lIdentifier<" + p_lIdentifier + ">)...");
                var db = DbHelper.DataBase;

                var dbCommand = db.GetNewCommand(DbFunction.DeleteSearcSave.szGetDescription(), false);
                db.AddInParameter(dbCommand, "p_lIdentifier", DbType.Int64, p_lIdentifier);
                
                db.ExecuteNonQuery(dbCommand);
            }
            catch (Exception ex)
            {
                 LogManager.Instance().LogError("DA_HistoricInfo --> DeleteHistoricSearcSave exception[" + ex.Message + "]");
            }
        }
       


    }
}
